Page({

  /**
   * 页面的初始数据
   */
  data: {
    current:0,
    newlist: ['股票','财经', '教育','科技'],
    hotlist:[],
    newtype:'',
    information_img: 'http://fxsc-1251880938.cosgz.myqcloud.com/image/zixun.png',
    business_img:'http://fxsc-1251880938.cosgz.myqcloud.com/image/chye.png',
    science_img: 'http://fxsc-1251880938.cosgz.myqcloud.com/image/kji.png',
      imgUrls: [
      'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
 
  },
  //页面跳转到文章列表
   tolist: function (e){
     var id = e.currentTarget.dataset.id
     wx.navigateTo({
       url: '../articleslist/articleslist?id='+id
     })
   },
  //横向页面切换处理函数
  ch_current: function(e){
    // console.log(e.target.dataset.id)
    var that = this
    var c = e.target.dataset.id
    that.setData({
      current: c
    })
    // console.log(that.data.newlist[c])
    var ty = that.data.newlist[c]
    that.setData({
      newtype:ty
    })
    wx.request({
      url: 'https://api.jisuapi.com/news/get',
      data: {
        channel: ty,
        num: '10',
        appkey: 'daff197b26137bcf'
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        //设置本地缓存操作(异步操作)
        wx.setStorage({
          key: ty,
          data: res.data.result,
        })
        //取本地缓存操作(同步操作)
        try {
          var value = wx.getStorageSync(ty)
          if (value) {
            that.setData({
              hotlist: res.data.result
            })
          }
        } catch (e) {
         console.log(e)
        }
      }
    }) 
  },
  //跳转到文章详情页
  todetails: function (e) {
    var that = this
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../articledetails/articledetails?id=' + id + '&newtype=' + that.data.newtype
    })
    //  console.log(url)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})